package com.pansoft.openplanet.adapter;

import android.content.Context;
import android.content.Intent;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.efounder.view.CircleImageView;
import com.pansoft.openplanet.R;
import com.pansoft.openplanet.activity.BuyTCActivity;
import com.pansoft.openplanet.activity.SellTCActivity;

/**
 * 交易市场adapter
 * Created by will on 18-3-28.
 */

public class MarketListAdapter  extends RecyclerView.Adapter<MarketListAdapter.ViewHolder>{

    private Context context;
    private boolean isSell;

    public MarketListAdapter(Context context, boolean isSell) {
        this.context = context;
        this.isSell = isSell;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.talk_chain_item_market_list, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(isSell){
                    Intent intent = new Intent(context, SellTCActivity.class);
                    context.startActivity(intent);
                    return;
                }
                Intent intent = new Intent(context, BuyTCActivity.class);
                context.startActivity(intent);
            }
        });

        if (isSell) {
            holder.tvBuy.setText("出售");
        }
        holder.tvBuy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(isSell){
                    Intent intent = new Intent(context, SellTCActivity.class);
                    context.startActivity(intent);
                    return;
                }
                Intent intent = new Intent(context, BuyTCActivity.class);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return 10;
    }

    public class ViewHolder extends RecyclerView.ViewHolder{

        ImageView ivAvatar;
        CircleImageView ivWxPay, ivAliPay;
        TextView tvSellerName;
        TextView tvPrice;
        TextView tvDealNum, tvGoodCommentsRate, tvCreditNum;
        TextView tvRestrictAmount;
        TextView tvBuy;
        View onlineIndicator;

        public ViewHolder(View itemView) {
            super(itemView);
            ivAvatar = itemView.findViewById(R.id.iv_avatar);
            ivWxPay = itemView.findViewById(R.id.iv_wx);
            ivAliPay = itemView.findViewById(R.id.iv_ali);
            tvSellerName = itemView.findViewById(R.id.tv_seller_name);
            tvPrice = itemView.findViewById(R.id.tv_price);
            tvDealNum = itemView.findViewById(R.id.tv_deal_number);
            tvGoodCommentsRate = itemView.findViewById(R.id.tv_good_comments_rate);
            tvCreditNum = itemView.findViewById(R.id.tv_credit_number);
            tvRestrictAmount = itemView.findViewById(R.id.tv_restrict_amount);
            tvBuy = itemView.findViewById(R.id.tv_buy);
            onlineIndicator = itemView.findViewById(R.id.view_online_indicator);
        }
    }
}
